package com.vcar.LDiceClient.module.loginModule
{
	import com.vcar.LDiceClient.config.MediatorName;
	import com.vcar.LDiceClient.config.ProxyNames;
	import com.vcar.LDiceClient.dataproxy.RequestMessage;
	import com.vcar.LDiceClient.dataproxy.SocketProxy;
	
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.ui.Keyboard;
	
	import mx.controls.ComboBox;
	import mx.events.ItemClickEvent;
	import mx.events.ListEvent;
	
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class loginModuleMediator extends Mediator
	{
		public function loginModuleMediator(viewComponent:Object=null)
		{
			super(MediatorName.loginModuleMediator, viewComponent);
			view.login_btn.addEventListener(MouseEvent.CLICK,loginBtn_click);
			view.login_btn.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
			view.username_txt.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
			view.password_txt.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
		}
		

		public function get view():loginModule
		{
			return viewComponent as loginModule;
		}
		
		private function loginBtn_click(event:Event):void
		{
			var reMessage:RequestMessage = new RequestMessage();
			var proxy:SocketProxy = facade.retrieveProxy(ProxyNames.SocketProxy) as SocketProxy;
			reMessage.type=2;
			reMessage.subtype=1;
			reMessage.params.userid=view.username_txt.text;
			reMessage.params.pwd=view.password_txt.text;
			proxy.send(reMessage);
		}
		
		private function keyDownHandler(e:KeyboardEvent):void
		{
			if(e.keyCode==Keyboard.ENTER){
				loginBtn_click(e);
			}
		}
		
		override public function onRemove() : void
		{
			view.login_btn.removeEventListener(MouseEvent.CLICK,loginBtn_click);
			view.login_btn.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
			view.username_txt.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
			view.password_txt.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
		}
	}
}